package com.guaoran.java8concurrency.java7;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;

/**
 * @author : guaoran
 * @Description : <br/>
 *  Fork/Join实例，并行框架
 * @date :2018/11/24 13:26
 */
public class ForkJoinDemo {
    public static void main(String[] args) {
        //并行：多核参与
        //并发：一同参与
        //ForkJoin 线程池
        System.out.println("当前公用ForkJoin线程池 并行数："+
                ForkJoinPool.commonPool().getParallelism());
        System.out.println("当前CPU处理器数："+
                Runtime.getRuntime().availableProcessors());
        //类似ThreadPoolExecutor
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        forkJoinPool.invoke(new RecursiveAction() {
            @Override
            protected void compute() {
                System.out.printf("[Thread Name :%s]Hello world....\n", Thread.currentThread().getName());
            }
        });
        forkJoinPool.shutdown();
    }
}
